package com.atguigu.lease.admin.task;



import com.atguigu.lease.admin.service.LeaseAgreementService;
import com.atguigu.lease.model.bean.LeaseAgreement;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;


/**
 * @author LOGIN
 * @title WebAdminTask
 * @create 2025/6/27 20:04
 * @description
 */
@Slf4j
@Component  //组件注解注入到ioc容器
public class WebAdminTask {
    @Autowired
    LeaseAgreementService leaseAgreementService;
    @Scheduled(cron = "0 0 0 * * *")
    public void checkLeaseAgrementstatus(){
        leaseAgreementService.update(Wrappers.lambdaUpdate(LeaseAgreement.class)
                .in(LeaseAgreement::getStatus, 2,5)
                .lt(LeaseAgreement::getLeaseEndDate,new Date())
                .set(LeaseAgreement::getStatus,4));
    }





    //启动了定时任务的项目，使用@Scheduled注解标注的，组件类方法，就是一个定时任务
    //可以在@Schedule注解中 通过cron属性设置cron表达式，指定定时任务执行的时间
/*    @Scheduled(cron="0/5 * * * * *")
    public void printHelloTask() {
        //定时任务的业务代码
        log.warn("定时任务执行了，当前时间: {} ",
                new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                        .format(new Date()));*/
        //System.out.println(new Date());
}
